package com.future.direction.common.util;

import com.future.direction.common.Constant;
import com.future.direction.common.bus.EventBusEvent;
import com.future.direction.common.bus.EventBusUtils;
import com.future.direction.data.bean.LoginBean;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by ZHP on 2018/12/28/0028.
 */

public class UserCacheUtil {
    /**
     * 保存登录用户信息
     *
     * @param loginBean
     */
    public static void saveInfo(LoginBean loginBean) {

        JPushInterface.setAlias(UIUtil.getContext(), Constant.alias, DeviceUtils.getAndroidID());

    }

    /**
     * 登录判断
     *
     * @return
     */
    public static boolean isLogin() {
        return true;
    }


    /**
     * token
     *
     * @return token
     */
    public static String getToken() {
        String token = ACache.get(UIUtil.getContext()).getAsString(Constant.token);
        return token;
    }

    /**
     * 退出登录以后删除用户信息
     */
    public static void loginOut() {
        EventBusUtils.sendEvent(new EventBusEvent<>(EventBusUtils.EventCode.VPN_CLOSE, EventBusUtils.EventCode.VPN_CLOSE));
        JPushInterface.deleteAlias(UIUtil.getContext(), Constant.alias);
        ACache aCache = ACache.get(UIUtil.getContext());
        aCache.clear();
//        SharedPreferences cookiePrefsFile = UIUtil.getContext().getSharedPreferences("CookiePrefsFile", 0);
//        SharedPreferences.Editor prefsWriter = cookiePrefsFile.edit();
//        prefsWriter.clear();
//        prefsWriter.apply();
    }



}
